// pages/finance-home/finance-home.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    filterActive:0,
    list:[]
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getTotalNum()
    this.getSupplierList(this.data.filterActive)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  onChange(event) {
    if (event.detail === 1) {
      wx.redirectTo({
        url: '/pages/mine/mine',
      })
    }
  },
  changeFilter(e){
    const val = e.currentTarget.dataset.val
    this.setData({ filterActive:val})
    this.getSupplierList(val)
  },
  getTotalNum(){
    app.reqFetch.selectTotalFinance({ }, (res) => {
      const { ntotalNum=0, ytotalNum=0, totalNum=0} =res.data
      this.setData({
        ntotalNum,
        ytotalNum,
        totalNum,
      })
    })
  },
  getSupplierList(type){
    app.reqFetch.selectSupplierFinance({
      isPayment: type
    }, (res) => {
    
        this.setData({list:res.data})
      })
  },
  toDetails(e){
    const { filterActive}=this.data
    const { supplierId, supplierName} = e.currentTarget.dataset.record
    wx.navigateTo({
      url: '/pages/finance-order/finance-order?data=' + JSON.stringify({ supplierId, filterActive, supplierName}),
    })
  },

  toReport(){
    wx.navigateTo({
      url: '/pages/finance-report/finance-report',
 
    })
  },
  
  toBatch() {
    wx.navigateTo({
      url: '/pages/finance-batch/finance-batch',

    })
  }
})